package YahooFinance.helper.updatethread;

import java.io.IOException;
import java.text.ParseException;
import java.util.Timer;
import java.util.TimerTask;

import YahooFinance.YahooQuoteFetcher;

/**
 * Simple demo that uses java.util.Timer to schedule a task to execute once 5
 * seconds have passed.
 */

public abstract class UpdateThread {
	Timer mTimer;
	YahooQuoteFetcher mFetcher;
	Object mWrapperObject;

	public UpdateThread(int pSeconds, YahooQuoteFetcher pFetcher , Object pCastToWhatever) {
		mFetcher = pFetcher;
		mTimer = new Timer();
		mWrapperObject = pCastToWhatever;
		mTimer.schedule(new RemindTask(),
                0,        //initial delay
                pSeconds * 1000);  //subsequent rate
		//start only one Thread
//		mTimer.schedule(new RemindTask(),
//                0);  //subsequent rate
	}
	
	public abstract void returnResults(String pReturnStatement);

	class RemindTask extends TimerTask {
		public void run() {
			try {
				mFetcher.getUpdate();
				
			} catch ( ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			}
			
			
		}
	}
}